<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
    xmlns:dssp="http://schemas.microsoft.com/xw/2004/10/dssp.html"
    xmlns:srf235="http://www.robot-electronics.co.uk/2006/10/srf235hardware.html"
    >

  <xsl:import href="/resources/dss/Microsoft.Dss.Runtime.Home.MasterPage.xslt" />

  <xsl:template match="/">
    <xsl:comment>
      <!-- Service Header Info -->
    </xsl:comment>
    <xsl:variable name="title">
      SRF235 Hardware Service
    </xsl:variable>
    <xsl:variable name="serviceName">
      SRF235 Hardware Service
    </xsl:variable>
    <xsl:variable name="description">
      The SRF235 is a narrow beam ultrasonic ranger, with a beam width of just 15°.
      An industrial high frequency air coupled transducer operating at 235KHz is
      used for both Transmit and Receive.
    </xsl:variable>

    <xsl:call-template name="MasterPage">
      <xsl:with-param name="serviceName" select="$serviceName" />
      <xsl:with-param name="description" select="$description" />
      <!-- If title is not provided, serviceName will be used instead. -->
      <xsl:with-param name="title">
        <xsl:value-of select="$serviceName" />
        <xsl:if test="$title != ''">
          <xsl:text> - </xsl:text>
          <xsl:value-of select="$title" />
        </xsl:if>
      </xsl:with-param>
      <!-- Possible values for navigation are: 'Open', 'Closed', and 'None'
           'Open' is the default value. -->
      <xsl:with-param name="navigation" select="'Open'" />
      <!-- The contents of head param will be placed just before the </head> tag in html. -->
      <xsl:with-param name="head">
        <link rel="stylesheet" type="text/css" href="/resources/I2CHardware/Devantech.Services.I2C.Hardware.resources.DevantechI2CHardware.Stylesheet.css" />

        <style type="text/css">
               /* Service-specific stylesheet goes here */
        </style>
        <script language="javascript" type="text/javascript">
          <![CDATA[<!--

/* Service-specific script goes here */

dssRuntime.init = function()
{
  // Add page initialization code here.
  // This function is attached to the window.onload event.
  // Do not override window.onload.
}

//-->     ]]>
        </script>
      </xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <!-- Match service state's document element. -->
	<xsl:template match="/srf235:SRF235HardwareState">
				<!--span class="PageName">SRF235 Hardware Service <img src="/resources/SRF235Hardware/Devantech.Services.SRF235.Hardware.resources.DevantechSRF235Hardware.Image.png"/></span-->

				<div class="RightColumn">
					<span class="SubTitle">
						<xsl:value-of select="count(srf235:Modules/*)" /> module<xsl:if test="count(srf235:Modules/*) &gt; 1">s</xsl:if> found
					</span>
				</div>
				<br clear="all"/>
				<xsl:for-each select="srf235:Modules/*">
					<div class="Module">
						<div class="RightColumn">
							<table class="Config">
								<tr>
									<th colspan="2">
										Config
									</th>
								</tr>
								<tr>
									<td class="SmallText">
										Auto-Poll
									</td>
									<td class="SmallText">
										<form method="POST">
                      <xsl:attribute name="id">
                        <xsl:text>EnablePolling</xsl:text>
                        <xsl:value-of select="srf235:I2CAddress" />
                        <xsl:text>Form</xsl:text>
                      </xsl:attribute>
											<input type="hidden" name="EnablePollingChange" value="true"/>
											<input type="hidden" name="I2CAddress">
												<xsl:attribute name="value">
													<xsl:value-of select="srf235:I2CAddress"/>
												</xsl:attribute>
											</input>
											<input id="EnablePolling" name="EnablePolling"
												title="Click to enable Polling of the sensor" type="checkbox">
                        <xsl:attribute name="onclick">
                          <xsl:text>document.getElementById('EnablePolling' + </xsl:text>
                          <xsl:value-of select="srf235:I2CAddress" />
                          <xsl:text> + 'Form').submit();</xsl:text>
                        </xsl:attribute>
												<xsl:if test="srf235:EnablePolling = 'true'">
													<xsl:attribute name="checked">CHECKED</xsl:attribute>
													<xsl:attribute name="value">on</xsl:attribute>
												</xsl:if>
											</input>
										</form>
									</td>
								</tr>

								<tr>
									<td class="SmallText">
										Delay
									</td>
									<td>
										<form method="POST">
                      <xsl:attribute name="id">
                        <xsl:text>PollDelay</xsl:text>
                        <xsl:value-of select="srf235:I2CAddress" />
                        <xsl:text>Form</xsl:text>
                      </xsl:attribute>
											<input type="hidden" name="I2CAddress">
												<xsl:attribute name="value">
													<xsl:value-of select="srf235:I2CAddress"/>
												</xsl:attribute>
											</input>
											<input id="PollDelay" class="Editable" maxlength="5" name="PollDelay"
												onfocus="this.className='EditableActive'" title="Click to change the Delay between panning or polling"
												type="text" >
                        <xsl:attribute name="onblur">
                          <xsl:text>this.className='Editable';document.getElementById('PollDelay' + </xsl:text>
                          <xsl:value-of select="srf235:I2CAddress" />
                          <xsl:text> + 'Form').submit();</xsl:text>
                        </xsl:attribute>
												<xsl:attribute name="value">
													<xsl:value-of select="srf235:PollDelay" />
												</xsl:attribute>
											</input>
										</form>
									</td>
								</tr>
							</table>
						</div>

						<span class="ModuleName">
							<form method="POST">
                <xsl:attribute name="id">
                  <xsl:text>NewI2CAddress</xsl:text>
                  <xsl:value-of select="srf235:I2CAddress" />
                  <xsl:text>Form</xsl:text>
                </xsl:attribute>
								SRF235 found at I2C Address
								<xsl:choose>
									<xsl:when test="count(//srf235:Modules/*) = 1">
										<input name="NewI2CAddress"
										class="Editable" maxlength="3" onblur="this.className='Editable';document.getElementById(this.id + 'Form').submit();"
										onfocus="this.className='EditableActive'" title="Click to Edit the I2C Address. NB: Make sure panning and polling are off!">
											<xsl:attribute name="value">
												<xsl:value-of select="srf235:I2CAddress"/>
											</xsl:attribute>
                      <xsl:attribute name="id">
                        <xsl:text>NewI2CAddress</xsl:text>
                        <xsl:value-of select="srf235:I2CAddress" />
                      </xsl:attribute>
										</input>
									</xsl:when>
									<xsl:otherwise>
										<xsl:value-of select="srf235:I2CAddress"/>
									</xsl:otherwise>
								</xsl:choose>
							</form>
						</span>
						<span class="SmallText">
							<xsl:value-of select="srf235:Timestamp"/>
						</span>
						<br/>
						<br/>
						<span class="key">
							Range:
						</span>
						<span class="value">
							<xsl:value-of select="srf235:Range"/>
						</span>
						
					</div>
				</xsl:for-each>
				<br clear="all" />
				<div class="hr"></div>
				<div class="RightColumn">
					<a class="LinkSmall" 
   href="http://www.robot-electronics.co.uk/htm/srf235tech.htm" 
   target="_new">View Devantech Documentation</a>
				</div>
				<span class="SmallText">Config at: /store/Devantech.Services.SRF235.Hardware.xml</span>
	</xsl:template>
</xsl:stylesheet>
